import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询客户资料管理
 */
export async function pageMesCustomerInformations(params) {
  const res = await request.get('/mes/mesCustomerInformation/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部客户资料管理
 */
export async function listMesCustomerInformations(params) {
  const res = await request.get('/mes/mesCustomerInformation/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询客户资料管理
 */
export async function getMesCustomerInformation(id) {
  const res = await request.get('/mes/mesCustomerInformation/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加客户资料管理
 */
export async function addMesCustomerInformation(data) {
  const res = await request.post('/mes/mesCustomerInformation', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改客户资料管理
 */
export async function updateMesCustomerInformation(data) {
  const res = await request.put('/mes/mesCustomerInformation', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除客户资料管理
 */
export async function removeMesCustomerInformation(id) {
  const res = await request.delete('/mes/mesCustomerInformation/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除客户资料管理
 */
export async function removeMesCustomerInformations(ids) {
  const res = await request.delete('/mes/mesCustomerInformation/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出客户资料管理
 */
export async function exportMesCustomerInformations(params) {
  const res = await request({
    url: '/mes/mesCustomerInformation/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `mesCustomerInformation_${Date.now()}.xlsx`);
}
